﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AdvantIQ.InstantCube.Model
{
    public class ModelErrorException : Exception
    {
        public List<object> SourcePath { get; set; }
        public string Description { get; set; }

        public ModelErrorException(object source, string description)
        {
            SourcePath = new List<object>();
            SourcePath.Add(source);
            Description = description;
        }

        public ModelErrorException(object source, ModelErrorException ex)
        {
            SourcePath = ex.SourcePath;
            SourcePath.Add(source);
            Description = ex.Description;
        }

        public string GetDescription()
        {
            var sb = new StringBuilder();
            foreach (var obj in ((IEnumerable<object>)SourcePath).Reverse())
            {
                sb.Append(obj.ToString());
                sb.Append(", ");
            }
            sb.Append(Description);

            return sb.ToString();
        }
    }
}
